package com.pine.manager.pineframework.convertors;

import com.pine.common.beans.pineframework.request.SysMenuQueryRequest;
import com.pine.common.beans.pineframework.request.SysMenuSaveOrUpdateRequest;
import com.pine.common.beans.pineframework.response.SysMenuQueryResponse;
import com.pine.common.convertor.EntityConvertor;
import com.pine.common.convertor.QueryConvertor;
import com.pine.common.convertor.SaveConvertor;
import com.pine.dao.pineframework.constants.MenuTypeEnum;
import com.pine.dao.pineframework.constants.VisibleEnum;
import com.pine.dao.pineframework.entity.SysMenu;
import com.pine.manager.pineframework.bo.SysMenuBo;
import com.pine.manager.pineframework.query.SysMenuQuery;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 菜单表 转换器
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public abstract class SysMenuConvertor implements EntityConvertor<SysMenu, SysMenuBo>,
        QueryConvertor<SysMenuBo, SysMenuQuery, SysMenuQueryRequest, SysMenuQueryResponse>,
        SaveConvertor<SysMenuBo, SysMenuSaveOrUpdateRequest> {

    @Override
    public abstract SysMenu entityBoToEntity(SysMenuBo sysMenuBo);

    @Override
    public abstract SysMenuBo entityToEntityBo(SysMenu sysMenu);

    @Override
    public abstract SysMenuQueryResponse entityBoToQueryResponse(SysMenuBo sysMenuBo);

    @Override
    public abstract SysMenuQuery queryRequestToQuery(SysMenuQueryRequest queryRequest);


    @Override
    public abstract List<SysMenu> entityBoToEntity(List<SysMenuBo> entityBo);

    @Override
    public abstract List<SysMenuBo> entityToEntityBo(List<SysMenu> entity);


    @AfterMapping
    public void afterMappingEntityBoToEntity(@MappingTarget SysMenu sysMenu, SysMenuBo sysMenuBo) {
        // entityBoToEntity() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToEntity()
    }

    @AfterMapping
    public void afterMappingEntityToEntityBo(@MappingTarget SysMenuBo sysMenuBo, SysMenu sysMenu) {
        // entityToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityToEntityBo()
    }

    @AfterMapping
    public void afterMappingQueryRequestToQuery(@MappingTarget SysMenuQuery sysMenuQuery, SysMenuQueryRequest sysMenuQueryRequest) {
        // queryRequestToQuery() 内部其它代码执行完之后，最后会自动执行 afterMappingQueryRequestToQuery()
    }

    @AfterMapping
    public void afterMappingEntityBoToQueryResponse(@MappingTarget SysMenuQueryResponse sysMenuQueryResponse, SysMenuBo sysMenuBo) {
        // entityBoToQueryResponse() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToQueryResponse()
    }


    public VisibleEnum integerToVisibleEnum(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return VisibleEnum.of(code);
    }

    public Integer visibleEnumToInteger(VisibleEnum visibleEnum) {
        if (Objects.isNull(visibleEnum)) {
            return null;
        }
        return visibleEnum.getCode();
    }

    public MenuTypeEnum integerToMenuTypeEnum(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return MenuTypeEnum.of(code);
    }

    public Integer menuTypeEnumToInteger(MenuTypeEnum menuTypeEnum) {
        if (Objects.isNull(menuTypeEnum)) {
            return null;
        }
        return menuTypeEnum.getCode();
    }
}
